
import Vue from 'vue';
import Vuex from 'vuex';
import * as types from './mutationType';
import CookieUtil from '../utils/cookieTool';

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    isLogin: CookieUtil.get('uuid') !== '',
    mobile: CookieUtil.get('mobile'),
    isAdmin: CookieUtil.get('admin') === '1',
  },
  mutations: {
    [types.CHANGELOGIN](state) {
      state.isLogin = !state.isLogin;
    },
    [types.GETMOBILE](state, mobile) {
      state.mobile = mobile;
    },
    [types.ISADMIN](state) {
      console.log(CookieUtil.get('admin'));
      state.isAdmin = CookieUtil.get('admin') === '1';
    },
  },
  actions: {
    [types.CHANGELOGIN]({ commit }) {
      commit(types.CHANGELOGIN);
    },
    [types.GETMOBILE]({ commit, state }, mobile) {
      commit(types.GETMOBILE, mobile);
    },
    [types.ISADMIN]({ commit, state }) {
      commit(types.ISADMIN);
    },
  },
});

export default store;
